Skip to content

fix(openai): preserve async parsing for streaming responses#607

Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
codex/openai-agents-streaming-response
Jul 21, 2026
Merged

fix(openai): preserve async parsing for streaming responses#607
Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
codex/openai-agents-streaming-response

Conversation

@cjgalione

@cjgalione Curtis Galione (cjgalione) commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

resolves https://linear.app/braintrustdata/issue/SDK-86/async-streaming-response-parsing-not-preserved

Summary

  • await asynchronous raw-response parsing before wrapping OpenAI Responses and Chat Completions streams
  • preserve the awaitable parse() contract exposed by with_streaming_response
  • extend existing cassette-backed streaming tests to await and consume the traced streams without mocks or new cassette churn

Root cause

openai.AsyncAPIResponse.parse() is asynchronous, but the tracing proxy replaced it with a synchronous method that returned the traced stream directly. The wrappers also attempted to instrument the un-awaited parser coroutine rather than the parsed iterator.

This broke callers such as OpenAI Agents that enter with_streaming_response and then call await api_response.parse(). Chat Completions had the same issue on its async raw streaming path.

The wrappers now detect and await asynchronous parsing before constructing the traced iterator, remember the original parse contract, and expose an awaitable parse() on the raw-response proxy. Synchronous raw-response behavior remains unchanged.

Validation

  • reproduced the Chat Completions failure with existing VCR coverage: parse() was not awaitable and the underlying parser coroutine was never awaited
  • full test_openai(latest) session with cassette playback: 70 tests passed, plus attachment and OpenRouter gateway suites
  • focused cassette playback for OpenAI 1.92.0, 1.77.0, and 1.71.0
  • pre-commit hooks: Ruff format/check, cassette consistency, pytest-pin synchronization, codespell, and whitespace checks

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) marked this pull request as ready for review July 21, 2026 17:41
Await async raw-response parsing before wrapping chat streams, and preserve the awaitable parse contract on the traced proxy. Reuse cassette-backed chat and Responses tests to cover real streaming behavior without mocks.
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) changed the title fix(openai): preserve async streaming response parsing fix(openai): preserve async parsing for streaming responses Jul 21, 2026
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 3725fa3 into main Jul 21, 2026
82 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the codex/openai-agents-streaming-response branch July 21, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants